package com.Register.controller.admin;

import com.Register.dto.AllCarouselsPageQueryDTO;
import com.Register.dto.CarouselDTO;
import com.Register.dto.CarouselsUpdateDTO;
import com.Register.entity.Carousel;
import com.Register.result.PageResult;
import com.Register.result.Result;
import com.Register.service.CarouselService;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

@RestController("webCarouselController")
@RequestMapping("/web/admin/carousel")
@Tag(name = "管理员端-轮播图相关接口")
@Slf4j
public class CarouselController {
    @Resource
    private CarouselService carouselService;
    /*
    管理员创建轮播图
     */
    @PostMapping("/create")
    @Operation(summary = "管理员创建轮播图")
    public Result<String> createCarousel(@RequestBody CarouselDTO carouselDTO) throws JsonProcessingException{
        return carouselService.createCarousel(carouselDTO);
    }

    @GetMapping("/page")
    @Operation(summary = "管理员分页查询轮播图")
    public Result<PageResult> getAllCarousels(@ParameterObject AllCarouselsPageQueryDTO allCarouselsPageQueryDTO){
        return Result.success(carouselService.getAllCarousels(allCarouselsPageQueryDTO));
    }

    @GetMapping("/{id}")
    @Operation(summary = "管理员根据id查询轮播图")
    public Result<Carousel> getCarouseByid(@PathVariable("id") Long id){
        return Result.success(carouselService.getCarouseByid(id));
    }

    @PutMapping("/update")
    @Operation(summary = "管理员更新轮播图")
    public Result<String> updateCarouse(@RequestBody CarouselsUpdateDTO carouselsUpdateDTO){
        return carouselService.updateCarouse(carouselsUpdateDTO);
    }
}
